package com.briup.smartcity_group7.service.impl;

import com.briup.smartcity_group7.bean.basic.Category;
import com.briup.smartcity_group7.dao.basic.CategoryMapper;
import com.briup.smartcity_group7.dao.ext.CategoryExtMapper;
import com.briup.smartcity_group7.service.ICategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private CategoryMapper mapper;
    @Autowired
    private CategoryExtMapper extMapper;

    @Override
    public PageInfo<Category> pageQueryAll(int pageNum, int pageSize) {
        return PageHelper.startPage(pageNum,pageSize).doSelectPageInfo(()->extMapper.all());
    }

    @Override
    public void deleteById(int id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void batchDelete(int[] ids) {

    }

    @Override
    public void saveCategory(Category category) {
        mapper.insert(category);
    }

    @Override
    public void updateCategory(Category category) {
        mapper.updateByPrimaryKeySelective(category);
    }

    @Override
    public List<Category> findAll() {
        return extMapper.all();
    }
}
